{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 自由市场模型\n",
    "\n",
    "经济学中最简单的模型就是自由市场中的供给-需求模型。它满足以下的供给曲线和需求曲线：\n",
    "\n",
    "线性需求曲线 $ Q = a_d - b_d p $\n",
    "\n",
    "线性供给曲线 $ Q = a_z + b_z (p - \\text{tax}) $\n",
    "\n",
    "其中$Q$是数量，$p$是价格，其他的都是参数，这里包含了向企业收税的情况。\n",
    "\n",
    "你的老板JL给你提出了以下要求：\n",
    "\n",
    "1. 要求你建立一个名为`Market`的python类 (class)。这个class就代表着一个市场。市场拥有的属性是 $a_d, b_d, a_z, b_z, \\text{tax}$。当给这些参数赋值之后，你就设计出了一个市场。\n",
    "\n",
    "2. 请建立一个市场，它的参数分别为$a_d = 15, b_d=0.5, a_z=-2, b_z=0.5, \\text{tax}=3$. 这个市场命名为`free_m`。\n",
    "\n",
    "\n",
    "3. 要求能通过`free_m.price()`计算出该市场的均衡价格。\n",
    "\n",
    "\n",
    "4. 要求能通过`free_m.quantity()`计算出该市场的均衡数量。\n",
    "\n",
    "\n",
    "5. 要求能通过`free_m.tax_revenue()`计算出在均衡情况下的总税收。\n",
    "\n",
    "\n",
    "6. 要求能通过`free_m.consumer_surplus()`计算出在均衡情况下的消费者剩余。同样，通过`free_m.producer_surplus()`计算出在均衡情况下的生产者剩余。\n",
    "\n",
    "\n",
    "7. 要求能通过`free_m.demand(p)`计算出价格为`p`时的需求为多少。\n",
    "\n",
    "\n",
    "8. 要求能通过`free_m.supply(p)`计算出价格为`p`时的供给为多少。\n",
    "\n",
    "\n",
    "9. 要求能通过`free_m.supply_no_tax(p)`计算出不收税情况下、价格为`p`时的供给为多少。\n",
    "\n",
    "\n",
    "10. 根据上面设计好的函数，画出收税与不收税时的需求-供给曲线。（坐标轴、legend什么的都要有）\n",
    "\n",
    "\n",
    "注：计算surplus需要积分，可以查`scipy`如何进行积分操作。Good luck!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- 少用for循环，多用[xxx for item in xxx].\n",
    "- 给class写好注释\n",
    "- 用好assert\n",
    "- 用一下*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
